package com.example.aerohub.pojo.resp;

import com.example.aerohub.exception.ErrorCode;
import lombok.Data;

import java.io.Serializable;

@Data
public class Resp<T> implements Serializable {
	
	private int marketErrorCode;

	private String marketErrorMsg;

	private T data;

	public Resp(int marketErrorCode, String marketErrorMsg, T data) {
		this.marketErrorCode = marketErrorCode;
		this.marketErrorMsg = marketErrorMsg;
		this.data = data;
	}

	public Resp(int marketErrorCode, String marketErrorMsg) {
		this.marketErrorCode = marketErrorCode;
		this.marketErrorMsg = marketErrorMsg;
		this.data = null;
	}

	public Resp(String marketErrorMsg) {
		this.marketErrorCode = 400;
		this.marketErrorMsg = marketErrorMsg;
		this.data = null;
	}

	public static <T> Resp<T> success(T data) {
		return new Resp<>(200, "Successful", data);
	}

	public static <T> Resp<T> error(ErrorCode errorCode) {
		return new Resp<>(errorCode.getCode(), errorCode.getMsg(), null);
	}

	public static <T> Resp<T> error(int code, String msg) {
		return new Resp<>(code, msg, null);
	}

	public static <T> Resp<T> error(String msg) {
		return new Resp<>(msg);
	}
}
